package com.yuqing.sentimentapp.utils;

import com.linkface.baselibrary.utils.SharedPrefUtils;
import com.yuqing.sentimentapp.Constants;
import com.yuqing.sentimentapp.channel.ChannelData;
import com.yuqing.sentimentapp.login.bean.LoginResultBean;

import java.util.List;

/**
 * Created by ShenHe on 2019/4/10.
 */

public class SharePrefrenceHelper {
    public static boolean checkLoginStatus(){
        return "true".equals(SharedPrefUtils.getString(Constants.STATUS_LOGIN));
    }

    public static void setLoginStatus(boolean status) {
        if (status) {
            SharedPrefUtils.saveString(Constants.STATUS_LOGIN, "true");
        } else {
            SharedPrefUtils.saveString(Constants.STATUS_LOGIN, "");
        }
    }

    public static String getLoginMobile() {
        return SharedPrefUtils.getString(Constants.MOBILE_LOGIN);
    }

    public static void setLoginMobile(String mobile) {
        SharedPrefUtils.saveString(Constants.MOBILE_LOGIN, mobile);
    }

    public static void setLoginResultBean(LoginResultBean bean) {
        SharedPrefUtils.putObject(Constants.LOGIN_RESULT_BEAN, bean);
    }

    public static LoginResultBean getLoginResultBean() {
        return (LoginResultBean) SharedPrefUtils.getObject(Constants.LOGIN_RESULT_BEAN);
    }

    public static void setUser(LoginResultBean.DataBean.UserBean user) {
        SharedPrefUtils.putObject(Constants.LOGIN_USER_BEAN, user);
    }

    public static LoginResultBean.DataBean.UserBean getUser() {
        return SharedPrefUtils.getObject(Constants.LOGIN_USER_BEAN);
    }

    public static String getToken() {
        return SharedPrefUtils.getString(Constants.TOKEN_LOGIN);
    }

    public static void setToken(String token) {
        SharedPrefUtils.saveString(Constants.TOKEN_LOGIN, token);
    }

    public static String getSearchHistoryData() {
        return SharedPrefUtils.getString(Constants.SEARCH_HISTORY_DATA);
    }

    public static void setSearchHistoryData(String searchHistory) {
        SharedPrefUtils.saveString(Constants.SEARCH_HISTORY_DATA, searchHistory);
    }

    public static void clearUserData() {
        setLoginStatus(false);
        setLoginMobile("");
        setLoginResultBean(new LoginResultBean());
        setToken("");
        setUser(new LoginResultBean.DataBean.UserBean());
    }

    public static void setIsVip(boolean isVip) {
        SharedPrefUtils.saveBoolean(Constants.LOGIN_USER_ISVIP, isVip);
    }

    public static boolean getIsVip() {
        return SharedPrefUtils.getBoolean(Constants.LOGIN_USER_ISVIP, false);
    }
}
